package com.meeruu.sg.account.core.api.constant;

import lombok.Getter;

/**
 * 账户用途
 *
 * @Auther: liwu
 * @Date: 2019/5/16 16:55
 * @Description:
 */
@Getter
public enum AccountUsage {

    GRANT(0, "F", "发放"),
    RECEIVED(1, "S", "收款"),
    REFUND(2, "T", "退款"),
    SETTLE(3, "J", "结算"),
    ACTIVITY(4, "H", "活动"),
    REDUCE(5, "K", "扣回"),
    ;
    private Integer code;
    private String prefix;
    private String desc;

    AccountUsage(Integer code, String prefix, String desc) {
        this.code = code;
        this.prefix = prefix;
        this.desc = desc;
    }

    public static AccountUsage getUsageByCode(Integer code) {

        if (null == code) {
            return null;
        }

        for (AccountUsage usage : values()) {
            if (usage.code == code) {
                return usage;
            }
        }

        throw new IllegalArgumentException("不支持的用途类型" + code);
    }
}
